/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package aspectualacme.impl;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import aspectualacme.AspectualComponent;
import aspectualacme.AspectualacmePackage;
import aspectualacme.AttachmentDeclaration;
import aspectualacme.BaseRole;
import aspectualacme.CrosscuttingRole;
import aspectualacme.Element;
import aspectualacme.Port;
import aspectualacme.Role;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Attachment Declaration</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link aspectualacme.impl.AttachmentDeclarationImpl#getAttachedBaseElement <em>Attached Base Element</em>}</li>
 *   <li>{@link aspectualacme.impl.AttachmentDeclarationImpl#getAttachedToElement <em>Attached To Element</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class AttachmentDeclarationImpl extends EObjectImpl implements AttachmentDeclaration {
	/**
	 * The cached value of the '{@link #getAttachedBaseElement() <em>Attached Base Element</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAttachedBaseElement()
	 * @generated
	 * @ordered
	 */
	protected Element attachedBaseElement;

	/**
	 * The cached value of the '{@link #getAttachedToElement() <em>Attached To Element</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAttachedToElement()
	 * @generated
	 * @ordered
	 */
	protected Element attachedToElement;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected AttachmentDeclarationImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return AspectualacmePackage.Literals.ATTACHMENT_DECLARATION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Element getAttachedBaseElement() {
		if (attachedBaseElement != null && attachedBaseElement.eIsProxy()) {
			InternalEObject oldAttachedBaseElement = (InternalEObject)attachedBaseElement;
			attachedBaseElement = (Element)eResolveProxy(oldAttachedBaseElement);
			if (attachedBaseElement != oldAttachedBaseElement) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, AspectualacmePackage.ATTACHMENT_DECLARATION__ATTACHED_BASE_ELEMENT, oldAttachedBaseElement, attachedBaseElement));
			}
		}
		return attachedBaseElement;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Element basicGetAttachedBaseElement() {
		return attachedBaseElement;
	}

	public void setAttachedToElement(Element newAttachedToElement) {
		if(newAttachedToElement != null && newAttachedToElement.getClass().getName().equals("aspectualacme.impl.PortImpl") && getAttachedBaseElement().getClass().getName().equals("aspectualacme.impl.CrosscuttingRoleImpl")){
				Port a = (Port)newAttachedToElement;
				a.getComponent().setIsAspect(true);		
		}
		Element oldAttachedToElement = attachedToElement;
		attachedToElement = newAttachedToElement;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(
					this,
					Notification.SET,
					AspectualacmePackage.ATTACHMENT_DECLARATION__ATTACHED_TO_ELEMENT,
					oldAttachedToElement, attachedToElement));
	}
	
	
	public void setAttachedBaseElement(Element newAttachedBaseElement) {
		if(newAttachedBaseElement != null && newAttachedBaseElement.getClass().getName().equals("aspectualacme.impl.PortImpl") && getAttachedToElement().getClass().getName().equals("aspectualacme.impl.CrosscuttingRoleImpl")){
			Port a = (Port)newAttachedBaseElement;
			a.getComponent().setIsAspect(true);		
		}	
		Element oldAttachedBaseElement = attachedBaseElement;
		attachedBaseElement = newAttachedBaseElement;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(
					this,
					Notification.SET,
					AspectualacmePackage.ATTACHMENT_DECLARATION__ATTACHED_BASE_ELEMENT,
					oldAttachedBaseElement, attachedBaseElement));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Element getAttachedToElement() {
		if (attachedToElement != null && attachedToElement.eIsProxy()) {
			InternalEObject oldAttachedToElement = (InternalEObject)attachedToElement;
			attachedToElement = (Element)eResolveProxy(oldAttachedToElement);
			if (attachedToElement != oldAttachedToElement) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, AspectualacmePackage.ATTACHMENT_DECLARATION__ATTACHED_TO_ELEMENT, oldAttachedToElement, attachedToElement));
			}
		}
		return attachedToElement;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Element basicGetAttachedToElement() {
		return attachedToElement;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case AspectualacmePackage.ATTACHMENT_DECLARATION__ATTACHED_BASE_ELEMENT:
				if (resolve) return getAttachedBaseElement();
				return basicGetAttachedBaseElement();
			case AspectualacmePackage.ATTACHMENT_DECLARATION__ATTACHED_TO_ELEMENT:
				if (resolve) return getAttachedToElement();
				return basicGetAttachedToElement();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case AspectualacmePackage.ATTACHMENT_DECLARATION__ATTACHED_BASE_ELEMENT:
				setAttachedBaseElement((Element)newValue);
				return;
			case AspectualacmePackage.ATTACHMENT_DECLARATION__ATTACHED_TO_ELEMENT:
				setAttachedToElement((Element)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case AspectualacmePackage.ATTACHMENT_DECLARATION__ATTACHED_BASE_ELEMENT:
				setAttachedBaseElement((Element)null);
				return;
			case AspectualacmePackage.ATTACHMENT_DECLARATION__ATTACHED_TO_ELEMENT:
				setAttachedToElement((Element)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case AspectualacmePackage.ATTACHMENT_DECLARATION__ATTACHED_BASE_ELEMENT:
				return attachedBaseElement != null;
			case AspectualacmePackage.ATTACHMENT_DECLARATION__ATTACHED_TO_ELEMENT:
				return attachedToElement != null;
		}
		return super.eIsSet(featureID);
	}

} //AttachmentDeclarationImpl
